#include <bits/stdc++.h>

#ifdef LLT_DBG
#define FR freopen("in.txt", "r", stdin)
#else
#define FR
#endif

using namespace std;
using ll = long long;

ll arr[1000005];
ll psum[1000005];
ll dp[1000005];

struct Point
{
    ll x, y;

    Point operator-(Point o) const
    {
        Point p;
        p.x = x - o.x;
        p.y = y - o.y;
        return p;
    }

    ll operator*(Point o) const
    {
        return x * o.y - y * o.x;
    }
};

bool check_convex(Point a, Point b, Point c)
{
    return (b - a) * (c - b) < 0;
}

void solve()
{
    int n;
    ll L;
    cin >> n >> L;

    L++;

    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        psum[i] = psum[i - 1] + arr[i];
    }

    for (int i = 1; i <= n; i++)
    {
        psum[i] = psum[i] + i;
    }

    vector<Point> convex;
    vector<int> idk;

    convex.push_back((Point){0, 0});
    idk.push_back(0);
    convex.push_back((Point){0, 0});
    idk.push_back(0);

    for (int i = 1; i <= n; i++)
    {
        ll k0 = 2 * psum[i];

        int l = 0;
        int r = (int)convex.size() - 2;

        while (l < r)
        {
            int mid = (l + r) / 2 + 1;

            if (convex[mid + 1].y - convex[mid].y < (convex[mid + 1].x - convex[mid].x) * k0)
                l = mid;
            else
                r = mid - 1;
        }
        l++;

        dp[i] = (psum[i] - psum[idk[l]] - L) * (psum[i] - psum[idk[l]] - L) + dp[idk[l]];

        Point p;

        p.x = psum[i];
        p.y = psum[i] * psum[i] + 2 * L * psum[i] + dp[i];

        while (convex.size() >= 2 && check_convex(convex[convex.size() - 2], convex[convex.size() - 1], p))
        {
            convex.pop_back();
            idk.pop_back();
        }

        convex.push_back(p);
        idk.push_back(i);
    }

    cout << dp[n] << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    FR;
    solve();
    return 0;
}